#include "executor.h"

char program[FILENAME_LENGTH],program_arg[FILENAME_LENGTH],config_path[FILENAME_LENGTH], stdout_file[FILENAME_LENGTH],stdin_file[FILENA
ME_LENGTH];
int time_limit;
int memory_limit;
int output_limit;

void getConfigFile(char *path)
{
  sprintf(config_path,"/proc/%d/exe",getpid());
  config_path[readlink(config_path,config_path,1023)]='\0';
  strrchr(config_path,'/')[1]=0;
  sprintf(&config_path[strlen(config_path)],path);
}

int main(int argc,char *argv[])
{
  memset(program, 0, FILENAME_LENGTH);
  memset(program_arg, 0, FILENAME_LENGTH);
  memset(config_path, 0, FILENAME_LENGTH);
  memset(stdout_file, 0, FILENAME_LENGTH);
  memset(stdin_file, 0, FILENAME_LENGTH);

  char *path = "executor.xml";
  if(argc > 1){
    path = argv[1];

  }

  getConfigFile(path);
  DPRINT("read config file : %s\n",config_path);
  read_config(config_path);
  int i;
  for (i=1;i<argc;i++)
    read_config(argv[i]);
  execute();
  return 0;

}
